package com.nightlife.model.rbac;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.ForeignKey;



/**
 * 资源表
 * @author Z.x.Y
 *
 */

@Entity
@Table(name="SYS_RESOURCE")
public class Resource implements Serializable{
	private static final long serialVersionUID = 1L;
	/**
	 * 资源ID
	 */
	@Id
	@GeneratedValue
	private int resourceId;
	/**
	 * 资源名
	 */
    private String name;
    /**
     * 资源路径
     */
    private String path;
    
    /**
     * 子资源
     */
    @OneToMany(mappedBy="parentResource")
    private Set<Resource> resources;
    
    /**
     * 父资源
     */
    @ManyToOne
    @JoinColumn(name="parentId")
    @ForeignKey(name="RESOURCE_FK")
    private Resource parentResource;
	
	public int getResourceId() {
		return resourceId;
	}
	public void setResourceId(int resourceId) {
		this.resourceId = resourceId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + resourceId;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Resource other = (Resource) obj;
		if (resourceId != other.resourceId)
			return false;
		return true;
	}
}
